package com.blue.integration.config;

import com.blue.integration.spring.amqp.FastJsonMessageConverter;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

/**
 * AmqpJsonConvertor 解析
 *
 * @author Jin Zheng
 * @since 1.0 2019-01-09
 */
public class AmqpJsonConvertorParser extends AbstractSimpleBeanDefinitionParser
{
	public AmqpJsonConvertorParser()
	{
	}

	@Override
	protected Class<?> getBeanClass(Element element)
	{
		return FastJsonMessageConverter.class;
	}

	@Override
	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder)
	{
		try
		{
			String compress = element.getAttribute("compress");
			builder.addPropertyValue("compress", compress);
		}
		catch (Exception e)
		{
			parserContext.getReaderContext().error(FastJsonMessageConverter.class.getName() + " 无法创建", element, null, e);
		}
	}
}
